/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package xowl.generator.proxy;

/**
 *
 * @author Laurent WOUTERS
 */
public class PropInterWriter {
    public static void write(java.io.Writer writer, xowl.generator.PropertyInterface inter) throws java.io.IOException {
        writer.write("    // <editor-fold defaultstate=\"collapsed\" desc=\"Property " + inter.getProperty().getName() + "\">\n");
        String type = null;
        if (inter.getRangeClass() != null)
            type = inter.getRangeClass().getJavaName();
        else
            type = inter.getRangeDatatype().getJavaType();
        if (inter.isVector())
            write_Vector(writer, type, inter);
        else
            write_Scalar(writer, type, inter);
        writer.write("    // </editor-fold>\n");
    }
    private static void write_Vector(java.io.Writer writer, String type, xowl.generator.PropertyInterface inter) throws java.io.IOException {
        String property = inter.getProperty().getName();
        property = String.valueOf(property.charAt(0)).toUpperCase() + property.substring(1);
        writer.append("    boolean add" + property + "(" + type + " elem);\n");
        writer.append("    boolean remove" + property + "(" + type + " elem);\n");
        if (!inter.getProperty().isObjectProperty() || !inter.isInTypeRestrictionChain())
            writer.append("    java.util.Collection<" + type + "> getAll" + property + "();\n");
        else
            writer.append("    java.util.Collection<" + type + "> getAll" + property + "As(" + type + " type);\n");
    }
    private static void write_Scalar(java.io.Writer writer, String type, xowl.generator.PropertyInterface inter) throws java.io.IOException {
        String property = inter.getProperty().getName();
        property = String.valueOf(property.charAt(0)).toUpperCase() + property.substring(1);
        writer.append("    boolean set" + property + "(" + type + " elem);\n");
        if (!inter.getProperty().isObjectProperty() || !inter.isInTypeRestrictionChain())
            writer.append("    " + type + " get" + property + "();\n");
        else
            writer.append("    " + type + " get" + property + "As(" + type + " type);\n");
    }
}
